import {
  getDistributionAreas
} from "@/api/superlinkAreat";
const state = {

  manufactureSiteList: [],//储存站点信息
}
const getters = {

}
const mutations = {
  setManufactureSiteList(state, data) {
    state.manufactureSiteList = data
  }
}

const actions = {

  // 获取全部站点信息
  async getDistributionAreas({ state, commit, dispatch }, token) {
    return new Promise(async (resolve, reject) => {
      const res = await getDistributionAreas(
        {
          page: 1,
          pageSize: 1000,
        },
      );
      let taskList = [ 'RBC531_CG', 'RBC531_ZK','RBC531_HX'];
      const { data } = res;
      const midList = data.results.filter((item) => {
        return taskList.includes(item.token)
      }) || [];
      let areaList = [{},{},{}]
      taskList.forEach((key,index) => {
        midList.forEach(e=>{
          if (key === e.token) {
            areaList[index] = e
          }
        })
      });
      console.log('area', areaList)
      if (!data.results || !data.results.length) {
        reject("暂无站点信息");
      }
      commit('setManufactureSiteList', areaList)
      resolve();
    });
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions, getters
}

